<?php

namespace app\api\controller;

use app\common\controller\Api;

use think\Db;


/**
 * 会员接口
 */
class Area extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    /**
     * 读取省市区数据,联动列表
     */
    public function getArea()
    {
        $params = $this->request->get();
        if (!empty($params)) {
            $province = isset($params['province']) ? $params['province'] : '';
            $city = isset($params['city']) ? $params['city'] : '';
        } else {
            $province = $this->request->get('province', '');
            $city = $this->request->get('city', '');
        }
        $where = ['pid' => 0, 'level' => 1];
        $provincelist = null;
        if ($province !== '') {
            $where['pid'] = $province;
            $where['level'] = 2;
            if ($city !== '') {
                $where['pid'] = $city;
                $where['level'] = 3;
            }
        }
        $provincelist = Db::name('area')->where($where)->field('id,name')->select();
        $this->success('城市列表', $provincelist);
    }
}
